    /* 
    * File:      GtkTextView演示 
    * Author:   blackboy,    blackboycpp@gmail.com 
    * D/T:       2010.9.29 
    */  
      
    #include <gtk/gtk.h>  
     GtkWidget * window2, *w3;
void destroyWindow2(GtkWidget *button, gpointer data);
void createWindow2(GtkWidget *button, gpointer data)
{
	if(w3 == NULL)	
		g_printf("before create:w3=NULL\n");
	else
		g_printf("before create:w3!=NULL\n");
	window2 = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_window_set_default_size(GTK_WINDOW(window2), 100,100);  
        g_signal_connect (window2, "destroy", destroyWindow2, NULL);
	gtk_widget_show(window2);
	w3 = window2;
	GtkStateType type = gtk_widget_get_state(w3);
	switch(type)
	{
		case GTK_STATE_NORMAL:g_printf("w3 is GTK_STATE_NORMAL \n");break;
		  case GTK_STATE_ACTIVE:g_printf("w3 is GTK_STATE_ACTIVE \n");break;
		  case GTK_STATE_PRELIGHT:g_printf("w3 is GTK_STATE_PRELIGHT \n");break;
		  case GTK_STATE_SELECTED:g_printf("w3 is GTK_STATE_SELECTED \n");break;
		  case GTK_STATE_INSENSITIVE:g_printf("w3 is GTK_STATE_INSENSITIVE \n");break;
		default:g_printf("neither \n");
	}
	if(G_IS_OBJECT(w3))
		g_printf("w3 is object,win2 type=%d \n", type);
	else 
		g_printf("w3 is not object \n");
}
void destroyWindow2(GtkWidget *button, gpointer data)
{
	//window2 = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	//gtk_window_set_default_size(GTK_WINDOW(window2), 100,100);  
        //g_signal_connect (window2, "destroy", gtk_main_quit, NULL);
	//g_object_unref(G_OBJECT(window2));
	

	gtk_widget_destroy(window2);	
	if(w3 == NULL)	
		g_printf("after create:w3=NULL\n");
	else
		g_printf("after create:w3!=NULL,\n");
	if(G_IS_OBJECT(w3))
		g_printf("w3 is object \n");
	else 
		g_printf("w3 is not object \n");
}
    int main (int argc, char *argv[])  
    {  
        GtkWidget* win, *vbox;  
        GtkWidget* button1;  
        GtkWidget* button2;  
        
      
        gtk_init (&argc, &argv);  
      
        win = gtk_window_new (GTK_WINDOW_TOPLEVEL);  
        gtk_container_set_border_width (GTK_CONTAINER (win),  1);  
        gtk_window_set_title (GTK_WINDOW (win), "GtkTextView Demo");  
        gtk_window_set_position (GTK_WINDOW (win), GTK_WIN_POS_CENTER);  
        gtk_window_set_default_size(GTK_WINDOW(win), 400,200);  
        g_signal_connect (win, "destroy", gtk_main_quit, NULL);  
	
	vbox = gtk_vbox_new(FALSE, 0);
	button1 = gtk_button_new_with_label("创建窗口");
	button2 = gtk_button_new_with_label("destroy");
        gtk_box_pack_start(GTK_BOX(vbox), button1, FALSE, FALSE, 5);
        gtk_box_pack_start(GTK_BOX(vbox), button2, FALSE, FALSE, 5);
        gtk_container_add(GTK_CONTAINER(win), vbox);

	g_signal_connect (G_OBJECT(button1), "clicked", G_CALLBACK(createWindow2), win);
	g_signal_connect (G_OBJECT(button2), "clicked", G_CALLBACK(destroyWindow2), NULL);
        gtk_widget_show_all(win);  
        gtk_main ();  
        return 0;  
    }  
